package com.xxjh.brs.mvc.advice;

import com.xxjh.brs.ftp.common.api.result.CommonResponse;
import com.xxjh.brs.ftp.common.exceptions.ConditionException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author CHENCHEN
 * @title a
 * @company 新兴际华科技（天津）有限公司
 * @create 2024-07-03 19:21
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionAdvice {

    @ExceptionHandler(value = Exception.class)
    public CommonResponse handlerBorderlessResourceStationException(HttpServletRequest request, Exception e){
        log.error("ExceptionAdvice receive Exception is : [{}]", e.getMessage(), e);
        if(e instanceof ConditionException){
            Integer code = ((ConditionException)e).getCode();
            return CommonResponse.EXCEPTION(code, e.getMessage());
        }
        return CommonResponse.EXCEPTION;
    }
}
